﻿#include "hzpch.h"

#include <GLFW/glfw3.h>
#include <glad/glad.h>
#include "OpenGLContext.h"

namespace Hazal
{
	COpenGLContext::COpenGLContext(GLFWwindow* windowHandle)
		: m_windowHandle(windowHandle)
	{
		HZ_CORE_ASSERT(m_windowHandle, "Window handle is NULL!")
	}

	void COpenGLContext::Init()
	{
		glfwMakeContextCurrent(m_windowHandle);								/// ����ָ�����ڵ�OpenGL������
		int nStatus = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);	/// ���ض�Ӧ��opengl�汾
		HZ_CORE_ASSERT(nStatus, "Failed to initilize Glad!")

		const unsigned char* ucVendor = const_cast<const unsigned char*>(glGetString(GL_VERSION));
		LOG_CORE_INFO("Vendor : {0}", (const char*)ucVendor);
	}
	
	void COpenGLContext::SwapBuffers()
	{
		/*The specified window must have an OpenGL or OpenGL ES context.
		Specifying a window without a context will generate a GLFW_NO_WINDOW_CONTEXT error.*/
		glfwSwapBuffers(m_windowHandle);	/// ����������
	}
}